package com.ms.service.module.account;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.xpec.c4.game.utility.GameUtility;
import com.xpec.c4.service.module.PropertyKey;
import com.xpec.c4.service.module.ServerProperties;

/**
 * 帳號認證方式
 */
public class AccountVerifyCheckWay {

	private static final Log log = LogFactory.getLog(AccountVerifyCheckWay.class);
	
	/** 不需要任何認證方式即為認證帳號 */
	private static final int DEFAULT_VERIFY = 1;

	/** 手機認證為必要 */
	private static final int PHONE = 2;
	
	/** 信箱認證為必要 */
	private static final int MAIL = 3;
	
	/** 手機及信箱認證皆為必要 */
	private static final int PHONE_AND_MAIL = 4;
	
	
	/**
	 * 當前設定的認證方式
	 */
	private static int verifyWay = DEFAULT_VERIFY;
	
	
	static{
		
		//從server_info_properties初始化
		String property = ServerProperties.getProperty(PropertyKey.account_verify_member_check);
		
		if(GameUtility.isHaveString(property)){
			try {
				verifyWay = Integer.valueOf(property);
			} catch (Exception e) {
				if(log.isErrorEnabled()){
					log.error("value of verify_member_check_method is not an Integer");
				}
			}	
		}
		else{
			if(log.isWarnEnabled()){
				log.warn("can't find property of verify_member_check_method in server_info_properties");
			}
		}
		
		if(log.isInfoEnabled()){
			log.info("verify_member_check_method="+verifyWay);
		}
		
	}

	/**
	 * 判定此帳號是否為認證帳號
	 */
	public static boolean isVerifyAccount(Account account){
		if(account == null){
			return false;
		}
		
		//根據當前的設定方式決定
		switch (verifyWay) {
		
			case DEFAULT_VERIFY:{
				return true;
			}
				
			case PHONE:{
				if(account.isHaveBindPhone()){
					return true;
				}
				else return false;
			}
				
			case MAIL:{
				if(account.isHaveBindMail()){
					return true;
				}
				else return false;
			}
				
			case PHONE_AND_MAIL:{
				if(account.isHaveBindPhone() && account.isHaveBindMail()){
					return true;
				}
				else return false;
			}
	
			default:{
				if(log.isErrorEnabled()){
					log.error("can't recognize verify way: "+verifyWay+", please check the initial process");
				}
				return false;
			}
			
		}
		
	}
	
}
